package initialize

import (
	"errors"
	"fmt"
	"github.com/go-redis/redis"
	"rpc/global"
)

func InitRedis() {
	res := global.AppData.Service.Redis
	global.RedisDB = redis.NewClient(&redis.Options{
		Addr:     fmt.Sprintf("%s:%d", res.Host, res.Port),
		Password: "", // no password set
		DB:       0,  // use default DB
	})
	pong, err := global.RedisDB.Ping().Result()
	if err != nil {
		panic(errors.New("redis链接失败"))
	}
	fmt.Println("redis 链接成功", pong)
	// Output: PONG <nil>
}
